﻿using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
[System.Serializable]
public class SpeedMove:Move{
    
    [HideInInspector]
    public Dir direction;				//The direction that the tank is facing. Used for movement direction.
    public Dir Direction
    {
        get { return direction; }
        set
        {
            if (value != direction)
            {
                switch (value)
                {
                    case Dir.Up:
                        tran.DORotate(new Vector3(0, 0, 0), 0f);
                        break;
                    case Dir.Down:
                        tran.DORotate(new Vector3(0, 180, 0), 0f);
                        break;
                    case Dir.Left:
                        tran.DORotate(new Vector3(0, -90, 0), 0f);
                        break;
                    case Dir.Right:
                        tran.DORotate(new Vector3(0, 90, 0), 0f);
                        break;
                    default:
                        break;
                }
                direction = value;
            }
            Moved();
        }
    }

    private void Moved()
    {
        rig.velocity = tran.forward  * moveSpeed;
    }

    public override void Start()
    {
        moveSpeed = 10;
    }
    public override void Updata()
    {
        base.Updata();
        if(isPlay1)
        {
            if (Input.GetKey(KeyCode.W))
            {
                Direction = Dir.Up;
            }
            if (Input.GetKey(KeyCode.S))
            {
                Direction = Dir.Down;
            }
            if (Input.GetKey(KeyCode.A))
            {
                Direction = Dir.Left;
            }
            if (Input.GetKey(KeyCode.D))
            {
                Direction = Dir.Right;
            }
        }
        else
        {
            if (Input.GetKey(KeyCode.UpArrow))
            {
                Direction = Dir.Up;
            }
            if (Input.GetKey(KeyCode.DownArrow))
            {
                Direction = Dir.Down;
            }
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                Direction = Dir.Left;
            }
            if (Input.GetKey(KeyCode.RightArrow))
            {
                Direction = Dir.Right;

            }
        }
    }
}
